package passworks;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Logger {

    public static int tabs = 0;
    public static boolean silent = false;

    private Logger() {
    }

    public static void SetSilent(boolean value) {
        silent = value;
    }

    public static boolean Read(String questionName) {
        BufferedReader keyboard;
        keyboard = new BufferedReader(
                new InputStreamReader(System.in));
        System.out.println(questionName + " (I/N)");
        try {
            if(keyboard.readLine().compareTo("I") == 0) {
                return true;
            }
        } catch (IOException e) {
            
        }
        return false;
    }

    /*
     * Roviden: Meg kell adni a hivo osztalyt, 
     * a fuggvenynevet, az iranyt(lasd. Directions.java)
     * es az adott elem indexet
     */
    public static void Print(String className, String functionName, Direction dir, int index) {
        if (!silent) {
            String outString = "";

            /*
             * tabok kiirasa
             */

            if (dir.equals(Direction.OUT)) {
                //Visszateresnel kiiras elott kell csokkenteni a formatum miatt
                tabs--;
            }
            for (int i = 0; i < tabs; ++i) {
                outString += "\t";
            }

            /*
             * irany
             */

            if (dir.equals(Direction.IN)) {
                outString += "-> ";
                //Tabok novelese
                tabs++;
            } else if (dir.equals(Direction.OUT)) {
                outString += "<- ";
            } else {
                //SINGLE: Egyszerre IN es OUT egy sorban
                outString += "<-> ";
            }

            /*
             * Osztaly[peldany].fuggveny() alakban
             */

            outString += className;
            // index=-1 -> nem tombos kiiras
            if (index >= 0) {
                outString += "[" + Integer.toString(index) + "]";
            }
            outString += "." + functionName + "();";

            System.out.println(outString);
        }
    }
}
